﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Collections;
using System.Reflection;
using UMC.Wiki.Entities;
using UMC.Data;
using UMC.Web;

namespace UMC.Wiki.Activities
{
    class SubjectStatusActivity : WebActivity
    {

        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            if (request.IsCashier)
            {

                var user = this.Context.Token.Identity();
                var Id = UMC.Data.Utility.UInt64Parse(this.AsyncDialog("Id", g =>
                {
                    return this.DialogValue(UMC.Data.Utility.NewId().ToString());
                })).Value;

                var sm = DataFactory.Instance().Subject(Id);
                var Status = Data.Utility.IntParse(this.AsyncDialog("Status", g =>
                {
                    if (sm != null)
                    {
                        var p = new Web.UIRadioDialog() { Title = "发布确认" };
                        p.Options.Add("不发布", "-1");
                        p.Options.Add("发布", "1");
                        return p;
                    }
                    else
                    {
                        var p = new Web.UIRadioDialog() { Title = "评论隐藏" };
                        p.Options.Add("隐藏", "-1");
                        p.Options.Add("显示", "1");
                        return p;
                    }


                }), 0);

                if (sm != null)
                {
                    if (Status > 0)
                    {

                        DataFactory.Instance().Put(new Subject
                        {
                            Id = Id,
                            Status = Status,
                            ReleaseTime = DateTime.Now,
                        });
                    }
                    else
                    {
                        DataFactory.Instance().Put(new Subject { Id = Id, Status = Status });
                    }
                }
                else
                {
                    DataFactory.Instance().Put(new Comment { Id = Id, Visible = Status }, false);

                }
                this.Prompt("设置成功");
            }
        }

    }
}